package com.corn.core.base.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;


public abstract  interface IBaseDao<PK, T>{
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>获取当前正在使用会话</p>
	 * <ul>
	 * <li>date:2014-7-20 下午02:13:29</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @return
	 */
	public Session getSession();  
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>持久化实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午01:21:36</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param entity
	 * @throws Exception
	 */
	public void save(T entity)throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>实体如果存在更新，否则持久化</p>
	 * <ul>
	 * <li>date:2014-7-20 下午01:22:43</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param entity
	 * @throws Exception
	 */
	public void saveOrUpdate(T entity) throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>根据索引删除实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午01:32:15</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param k
	 * @throws Exception
	 */
	public void delete(PK k)throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>根据索引集批量删除实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午01:32:50</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param ks
	 * @throws Exception
	 */
	public void delete(PK[] ks)throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>删除实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午01:26:07</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param entity
	 * @throws Exception
	 */
	public void deleteEntity(T entity)throws Exception;
	
	
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>批量删除实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午01:26:35</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param entitys
	 * @throws Exception
	 */
	public void deleteEntity(T[] entitys)throws Exception;
	/**
	 * <b>note</b>
	 * <p>根据唯一索引获取唯一实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午01:56:55</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param k
	 * @return
	 * @throws Exception
	 */
	public T get(PK k) throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>延迟加载单个实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午02:07:58</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param k
	 * @return
	 * @throws Exception
	 */
	public T load(PK k) throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>延迟加载所有实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午02:08:18</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @return
	 * @throws Exception
	 */
	public List<T> loadAll() throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>更新实体</p>
	 * <ul>
	 * <li>date:2014-7-20 下午02:11:41</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param entity
	 * @throws Exception
	 */
	public void modify(T entity)throws Exception;

    
    /**
     * 
     *
     * <b>note</b>
     * <p>hibernate 规则查询</p>
     * <ul>
     * <li>date:2014-7-20 下午03:19:11</li>
     * <li>mail:cloudsinthewind@163.com</li>
     * </ul>
     * @author madong
     * @version v1.0
     * @param criteria
     * @param firstResult
     * @param maxResults
     * @return
     * @throws Exception
     */
	public List<?> findByCriteria(DetachedCriteria criteria, int firstResult,int maxResults) throws Exception ;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>hibernate 规则查询</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:19:16</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param criteria
	 * @return
	 * @throws Exception
	 */
	public List<?> findByCriteria(DetachedCriteria criteria) throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>hibernate 规则查询查询总记录数</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:23:55</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param criteria
	 * @return
	 * @throws Exception
	 */
	public int findByCriteriaCount(DetachedCriteria criteria) throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>单个动态参数查询</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:19:20</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param hql
	 * @param paramName
	 * @param value
	 * @return
	 * @throws Exception
	 */
	public List<?> findByNamedParam(String hql, String paramName, Object value)throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>单个动态参数查询 查询总记录</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:24:55</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param hql
	 * @param paramName
	 * @param value
	 * @return
	 * @throws Exception
	 */
	public int findByNamedParamCount(String hql,String paramName,Object value) throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>动态参数查询</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:19:24</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param hql
	 * @param paramName
	 * @param values
	 * @return
	 * @throws Exception
	 */
	public List<?> findByNamedParam(String hql, String[] paramName,Object[] values) throws Exception ;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>动态参数查询 总记录数</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:25:32</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param hql
	 * @param paramName
	 * @param values
	 * @return
	 * @throws Exception
	 */
	public int findByNamedParamCount(String hql,String[] paramName,Object[] values) throws Exception;
	
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>指定参数站位符号查询??</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:19:28</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param hql
	 * @param values
	 * @return
	 * @throws Exception
	 */
	public List<?> findByNamedQuery(String hql, Object[] values)throws Exception;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>批量修改 底层调用bulkUpdate(hql)</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:19:33</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param hql
	 * @return
	 * @throws Exception
	 */
	public int modifyBatch(String hql) throws Exception ;
	/**
	 * 
	 *
	 * <b>note</b>
	 * <p>批量修改 底层调用bulkUpdate(hql, values)</p>
	 * <ul>
	 * <li>date:2014-7-20 下午03:19:36</li>
	 * <li>mail:cloudsinthewind@163.com</li>
	 * </ul>
	 * @author madong
	 * @version v1.0
	 * @param hql
	 * @param values
	 * @return
	 * @throws Exception
	 */
	public int modifyBatch(String hql, Object[] values)throws Exception ;
	
	
}
